/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.io.*;
import java.util.*;
import java.sql.*;

public class EnrollFormBean {

    public String firstname;
    public String lastname;
    public String emailid;
    public String billaddress;
    public String seques;
    public String secans;
    public String billpayid;
    public String password;
    public String cnfpassword;
    public String custid;
    public Hashtable errors;
    public DbConnect dbc;

    public boolean validate() {
        boolean bool = true;
        if (firstname.equals("")) {
            errors.put("firstname", "Please enter your first name");
            firstname = "";
            bool = false;
        }
        if (lastname.equals("")) {
            errors.put("lastname", "Please enter your last name");
            lastname = "";
            bool = false;
        }

        if (emailid.equals("") || (emailid.indexOf('@') == -1)) {
            errors.put("emailid", "Please enter a valid email address");
            emailid = "";
            bool = false;
        }
        if (billaddress.equals("")) {
            errors.put("billaddr", "Please enter a Bill Address");
            billaddress = "";
            bool = false;
        }
        if (seques.equals("")) {
            errors.put("seques", "Please enter a valid Security Question");
            seques = "";
            bool = false;
        }
        if (secans.equals("")) {
            errors.put("secans", "Please enter a valid Mobile Number");
            secans = "";
            bool = false;
        }
        if (billpayid.equals("")) {
            errors.put("billid", "Please enter a valid Mobile Number");
            billpayid = "";
            bool = false;
        }
        if (!password.equals("") && (cnfpassword.equals("")
                || !password.equals(cnfpassword))) {
            errors.put("cnfpassword", "Please confirm your password");
            password = "";
            bool = false;
        }



        return bool;
    }

    public String getErrorMsg(String s) {
        String errorMsg = (String) errors.get(s.trim());
        return (errorMsg == null) ? "" : errorMsg;
    }

    public EnrollFormBean() {
        firstname = "";
        lastname = "";
        emailid = "";
        billaddress = "";
        seques = "";
        secans = "";
        billpayid = "";
        password = "";
        cnfpassword = "";
        errors = new Hashtable();
    }

    public String getFirstName() {
        return firstname;
    }

    public String getLastName() {
        return lastname;
    }

    public String getEmailId() {
        return emailid;
    }

    public String getBillAddress() {
        return billaddress;
    }

    public String getSeques() {
        return seques;
    }

    public String getSecans() {
        return secans;
    }

    public String getBillpayid() {
        return billpayid;
    }

    public String getPassword() {
        return password;
    }
        public String getCust() {
        return custid;
    }

    public void setFirstName(String fname) {

        firstname = fname;
    }

    public void setLastName(String lname) {

        lastname = lname;
    }

    public void setEmailId(String eml) {


        emailid = eml;
    }

    public void setBillAddress(String eml) {


        billaddress = eml;
    }

    public void setSeques(String z) {

        seques = z;
    }

    public void setSecans(String z) {

        secans = z;
    }

    public void setBillpayid(String z) {

        billpayid = z;
    }

    public void setPassword(String eml) {


        password = eml;
    }

    public void setCnfpass(String eml) {

        cnfpassword = eml;
    }

   

    public boolean match() {

        boolean flag = false;
        Connection con = null;

dbc=new DbConnect();
System.out.println(getCust());
        try {
            con = dbc.getOracleConnection();
            Statement st = con.createStatement();

            st.executeUpdate("update onbill_customer set billstatus=1 where custid="+getCust());
            st.executeUpdate("commit");
            ResultSet res = st.executeQuery("select * from onbill_customer where custid="+getCust());
            res.next();
            if (res.getString(2).equals(firstname)) {
                flag = true;
            } else {
                errors.put("database", "Data Do Not Match");
            }









        } catch (Exception e) {
            e.printStackTrace();
        }

        return flag;
    }
}
